const fs = require('fs');

/**
 * 判断是否是文件夹
 * @param {*} path
 * @returns
 */
function isDirectory(path){
    if (!path) {
        throw new Error('未获取到目录路径')
    }
    return fs.statSync(path).isDirectory()
}

/**
 * 清空文件夹内指定后缀名的文件
 * @param {*} path
 * @param {string} [suffix='']
 */
function clearDirSync(path, suffix = '') {
    if (!path) {
        throw new Error('未获取到目录路径')
    }
    const files = fs.readdirSync(path)

    files.forEach(file => {
        if (file.includes(suffix)) {
            fs.rmSync(path +'/'+ file);
        }
    })
}

module.exports = {
    isDirectory,
    clearDirSync
}